import {ElMessage} from "element-plus";

export function downloadBlob(blob: Blob, fileName:string) {
    try {
        console.log(blob)
        const href = window.URL.createObjectURL(blob) // 创建下载的链接
        // if (window.navigator.msSaveBlob) {
        //     window.navigator.msSaveBlob(blob, fileName)
        // } else {
            const downloadElement = document.createElement('a')
            downloadElement.href = href
            downloadElement.target = '_blank'
            downloadElement.download = fileName
            document.body.appendChild(downloadElement)
            downloadElement.click() // 点击下载
            document.body.removeChild(downloadElement) // 下载完成移除元素
            window.URL.revokeObjectURL(href) // 释放掉blob对象
        // }
    } catch (e) {
        console.log(e)
        ElMessage.error('下载失败')
    }
}
